# -*- coding: utf-8 -*-

from datetime import timedelta

from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dim.dim_yl_oms_order_interceptor_hi import jms_dim__dim_yl_oms_order_interceptor_hi
from jms_hi.dwd.oms.dwd_yl_oms_oms_order_hf import jms_dwd__dwd_yl_oms_oms_order_hf
from jms_hi.dwd.sqs.dwd_abnormal_event_hi import jms_dwd__dwd_abnormal_event_hi
from jms_hi.dwd.tab.dwd_tab_barscan_arrival_base_hi import jms_dwd__dwd_tab_barscan_arrival_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_bagging_base_hi import jms_dwd__dwd_tab_barscan_bagging_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_collect_base_hi import jms_dwd__dwd_tab_barscan_collect_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_deliver_base_hi import jms_dwd__dwd_tab_barscan_deliver_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_difficult_base_hi import jms_dwd__dwd_tab_barscan_difficult_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_loading_base_hi import jms_dwd__dwd_tab_barscan_loading_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_send_base_hi import jms_dwd__dwd_tab_barscan_send_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_sign_base_hi import jms_dwd__dwd_tab_barscan_sign_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_taking_base_hi import jms_dwd__dwd_tab_barscan_taking_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_unloading_base_hi import jms_dwd__dwd_tab_barscan_unloading_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_warehousing_base_hi import jms_dwd__dwd_tab_barscan_warehousing_base_hi
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dm__dm_epidemic_difficult_monitor_details = SparkSqlOperator(
    task_id='jms_dm__dm_epidemic_difficult_monitor_details',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_epidemic_difficult_monitor_details_{{ execution_date | cst_hour }}',
    sql='jms_hi/dm/dm_epidemic_difficult_monitor_details/execute.sql',
    pool_slots=5,
    driver_cores=2,
    executor_cores=4,
    executor_memory='12G',
    driver_memory='4G',
    num_executors=30,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 40,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold': 52428800,  # MapJoin 阈值 100M
          'spark.sql.shuffle.partitions': 400,
          },
    hiveconf={
        'hive.exec.dynamic.partition': 'true',  # 动态分区
        'hive.exec.dynamic.partition.mode': 'nonstrict',
        'hive.exec.max.dynamic.partitions': 600,  # 每天生成 20 个分区
        'hive.exec.max.dynamic.partitions.pernode': 40,  # 每天生成 20 个分区
    },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_epidemic_difficult_monitor_details << [
    jms_dim__dim_yl_oms_order_interceptor_hi,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_abnormal_event_hi,
    jms_dwd__dwd_tab_barscan_arrival_base_hi,
    jms_dwd__dwd_tab_barscan_bagging_base_hi,
    jms_dwd__dwd_tab_barscan_collect_base_hi,
    jms_dwd__dwd_tab_barscan_deliver_base_hi,
    jms_dwd__dwd_tab_barscan_difficult_base_hi,
    jms_dwd__dwd_tab_barscan_loading_base_hi,
    jms_dwd__dwd_tab_barscan_send_base_hi,
    jms_dwd__dwd_tab_barscan_sign_base_hi,
    jms_dwd__dwd_tab_barscan_taking_base_hi,
    jms_dwd__dwd_tab_barscan_unloading_base_hi,
    jms_dwd__dwd_tab_barscan_warehousing_base_hi,
    jms_dwd__dwd_yl_oms_oms_order_hf
]